const logger = require('./logger')

const response = {
    success: (ctx, { message = 'success', data = null, status = 200 }) => {
        ctx.status = status;
        ctx.body = {
            code: status,
            message: message,
            data: data
        };
        // logger.error('这是一个错误信息');  // 会写入 error.log 和 combined.log
        // logger.warn('这是一个警告信息');   // 会写入 combined.log
        logger.info(`[Response] ${ctx.method} ${ctx.path} -> ${status} ${message}`);   // 会写入 combined.log
        // 添加日志记录
        console.log(`[Response] ${ctx.method} ${ctx.path} -> ${status} ${message}`);
    },
    error: (ctx, { message = 'error', status = 201 }) => {
        ctx.status = status;
        ctx.body = {
            code: status,
            message: message,
        };
        logger.warn(`[Response] ${ctx.method} ${ctx.path} -> ${status} ${message}`);
        // 添加日志记录
        console.log(`[Response] ${ctx.method} ${ctx.path} -> ${status} ${message}`);
    }


}
module.exports = response